#ifndef HCONCURRENT_H
#define HCONCURRENT_H

#include <QRunnable>
#include <functional>
#include <thread>
#include <future>

// 定义一个函数模板，用来接受不定参数的函数指针

class HConcurrent : public QRunnable
{
public:
    template<typename ClassName, typename... Args>
    static void call(void* obj, std::function<void(Args...)> func, Args... args) {
        func(args...);
        std::thread(func, obj);
    }

protected:
    void run();
private:
};

class Coroutine {
public:
    Coroutine() : value_future(promise.get_future()) {}
    int GetValue() {
        if (value_future.wait_for(std::chrono::seconds(0)) == std::future_status::deferred) {
            return value_future.get();
        }
        return value_future.get();
    }

    void SetValue(int value) {
        promise.set_value(value);
    }

private:
    std::promise<int> promise;
    std::future<int> value_future;
};

#endif // HCONCURRENT_H
